package cn.xunjie.ymcc.mq.consumer;

import cn.xunjie.ymcc.domain.CourseOrder;
import cn.xunjie.ymcc.dto.PayNotifyDto;
import cn.xunjie.ymcc.service.ICourseOrderService;
import cn.xunjie.ymcc.util.AssertUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@RocketMQMessageListener(
        consumerGroup = "course-order-paynotify-consumer",
        topic = "paytimeout-topic",
        selectorExpression = "paytimeout-tag",
        messageModel = MessageModel.BROADCASTING//广播模式

)
public class PayTimeOutConumer implements RocketMQListener<MessageExt> {
    @Autowired
    private ICourseOrderService courseOrderService;
    @Override
    public void onMessage(MessageExt messageExt) {
        byte[] body = messageExt.getBody();
        if(body == null || body.length == 0){
            return;
        }
        String orderNo = new String(body, StandardCharsets.UTF_8);
        courseOrderService.cancelOrder(orderNo);

    }
}
